package com.neusoft.databus.policy.model;

import java.util.Date;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.ManyToOne;
import javax.persistence.OneToOne;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;

import org.hibernate.validator.constraints.Length;

import com.neusoft.bizcore.web.jpa.model.AbstractAuditModel;
import com.neusoft.databus.policy.enums.EventStatus;

import lombok.Getter;
import lombok.Setter;

/**
 * 事件(报警)
 *
 * @author naxiang
 */
@Getter
@Setter
@Entity
public class Event extends AbstractAuditModel {

    private static final long serialVersionUID = 8779565525426024802L;

    /**
     * 事件编码
     */
    @NotBlank(message = "事件编码不能为空")
    @Length(max = 255, message = "事件编码不能超过{max}位")
    @Column(length = 255, nullable = false)
    private String code;

    /**
     * 事件状态
     */
    @Enumerated(EnumType.STRING)
    @NotNull(message = "事件状态不能为空")
    @Column(nullable = false)
    private EventStatus status;

    /**
     * 事件级别,存放子系统推送的告警信息事件等级
     */
    @Length(max = 50, message = "事件级别不能超过{max}位")
    @Column(length = 50)
    private String priority;

    /**
     * 事件解除时间
     */
    @Column(nullable = true)
    private Date fixTime;

    /**
     * 资源编码唯一标识
     */
    @NotBlank(message = "资源编码不能为空")
    @Length(max = 255, message = "资源编码不能超过{max}位")
    @Column(length = 50, nullable = false)
    private String resourceCode;

    //	/**
    //	 * 策略id TODO: delete
    //	 */
    //	@Column(length = 50, nullable = false)
    //	private Long policyId;
    //
    //	/**
    //	 * 策略编码 TODO: delete
    //	 */
    //	@Length(max = 255, message = "策略编码不能超过{max}位")
    //	@Column(length = 100, nullable = false)
    //	private String policyCode;

    @ManyToOne
    private Policy policy;

    /**
     * 关联事件属性
     */
    @OneToOne(targetEntity = EventAttribute.class, cascade = {CascadeType.PERSIST })
    private EventAttribute eventAttribute = new EventAttribute();

    /**
     * 指标编码
     */
    @Length(max = 255, message = "指标编码不能超过{max}位")
    @Column(length = 100)
    private String metricCode;
}
